/*
 * @Author: scl
 * @Date: 2023-06-09 16:14:56
 * @LastEditTime: 2023-06-10 12:13:00
 * @Description: file content
 */
/*
 * @lc app=leetcode.cn id=67 lang=typescript
 *
 * [67] 二进制求和
 */

// @lc code=start
function addBinary(a: string, b: string): string {
    const len1:number=a.length,len2:number=b.length
    let len:number,i:number=len1,j:number=len2,temp:number,temp1:number=0
    let str:string='',str1:string
    while(i&&j)
    {
        i--,j--
        temp=a[i]===b[j]?0:1
        if(temp1==1&&temp==0&&a[i]=='1'){
            str.concat('1')
        }else if(temp1==1&&temp==0&&a[i]=='0'){
            str.concat('1')
            temp1=0
        }else if(temp1==1&&temp==1){
            str.concat('0')
        }
        str=str.concat(String(temp))
        if(temp==0&&a[i]=='1'){
            temp1=1
        }else{
            temp1=0
        }
    }
    str1=i?a.substring(0,i):b.substring(0,j)
    len=str1.length
    while(temp1==1&&len){
        len--
        if(str1[len]=='1'){
            str='0'.concat(str)
        }else{
            str='1'.concat(str)
            temp1=0
            str1=str1.substring(0,len)
        }
    }
    str=str1.concat(str)
    return str
};
// @lc code=end

